home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The PC-SIG Library 10
/
The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso
/
PC_SIGCD
/
05
/
6
/
DISK0564.ZIP
/
SOURCE.ARC
/
CLEAN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-07-09
|
2KB
|
59 lines
/* this program removes all control characters from a file (except
for carriage return, line feed, form feed, tab, and backspace, which
it leaves alone */
/* It reads from a file if a file name is specified, or from the
standard input if no file name is given. It writes to the standard
output */
/* by Jon Dart, 3012 Hawthorn St., San Diego, CA 92104 */
/* version 1.0, 16-Nov-86 */
#include <stdio.h>
#include <fcntl.h>
#define PATHSIZE 65 /* max size of DOS pathname + 1 */
#define BUFSIZE 16384 /* input buffer size */
#define EOF -1
#define CR (unsigned char) '\015'
#define LF (unsigned char) '\012'
#define FF (unsigned char) '\014'
#define BKS (unsigned char) '\010'
#define TAB (unsigned char) '\011'
#define CTRLZ (unsigned char) '\032'
extern char *malloc();
main(argc,argv)
int argc; char **argv;
{
FILE *infd;
register int c;
unsigned char *buffer;
buffer = (unsigned char *) malloc(BUFSIZE);
if (argc>=2) {
infd = fopen(argv[1],"r");
if (infd == NULL) {
fprintf(stderr,"\nCan't open: %s\n",argv[1]);
exit(1);
}
}
else /* read from std input */
infd = stdin;
setbuf(infd,buffer);
while ((c=getc(infd)) != EOF) {
c = c & 0177; /* strip hi bit */
if (c==CTRLZ)
break;
else if ( (c>=32 && c!=0177)
|| (c==CR) || (c==LF) || (c==BKS) || (c==TAB) || (c==FF) )
putc(c,stdout);
}
if (ferror(infd)) fprintf(stderr,"clean: error in reading file\n");
if (ferror(stdout)) fprintf(stderr,"clean: error in writing file\n");
fclose(infd);
}